<template>
	<view>
		<view class="fixed">
			<!-- 状态栏 -->
			<view class="statusBar" :style="'height:'+statusBarHeight+'px'"></view>
			<view class="myheader padding-sm font-sub-title">
				<text class="cuIcon-back margin-right-ssm" @click="back()"></text>
				签约请求
			</view>
		</view>
		<view v-if="varList.length==0"  class="no_data">
			<image src="../../static/img/no_data.png" class="no_data_img" mode="widthFix"></image>
			<view class="font-sub-title">暂无数据</view>
		</view>
		<view v-else class="cu-list menu sm-border" :style="{marginTop:navHeight}">
			<view v-for="data in varList" class="cu-item bg-white arrow" style="padding-right: 30px;">
				<view class="content padding-xs flex justify-between">
					<view style="display: block;"  @tap="jump('/pages/health/report/index')">
						<view style="line-height: 1.3;">
							<text class=" margin-right font-normal">{{data.name}}</text>
							<text class="font-small margin-right text-light-gray">{{data.sex=='1'?'男':'女'}}</text>
							<text class="font-small margin-right text-light-gray">{{getAge(data.idcard)}}岁</text>
						</view>
						<view style="line-height: 1.3;">
							<text class="font-small margin-right text-light-gray">{{data.city}}{{data.district}}</text>
						</view>
					</view>
					<view class="flex align-center justify-end">
						<view> 
							<button class="cu-btn bg-green margin-right font-normal" @tap="agree(data.contractedCareId)">同意</button>
							<button class="cu-btn bg-red  font-normal" @tap="deny(data.contractedCareId)">拒绝</button>
						</view>
					</view>
					
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	var that;
	export default {
		computed:{
			...mapGetters(['navHeight']),
		},
		data() {
			return {
				statusBarHeight:Vue.prototype.StatusBar,
				varList:[],
				user:'',
			}
		},
		onLoad(){
			that =this;
			this.user = uni.getStorageSync("userInfo")
			this.getData()
		},
		onShow(){
			uni.hideTabBarRedDot({
				index:3
			})
		},
		onPullDownRefresh(){
			this.getData()
		},
		methods: {
			getData(){
				this.$http.getApplySignList().then((res)=>{
					uni.stopPullDownRefresh()
					that.varList = res.result;
				})
			},
			agree(id){
				this.$http.agreeSign({
					contractedCareId:id
				}).then((res)=>{
					if(res.code==1){
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: '操作成功！'
						});
						that.getData();
					}else{
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: res.message
						});
					}
				})
			},
			deny(id){
				this.$http.denySign({
					contractedCareId:id
				}).then((res)=>{
					if(res.code==1){
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: '操作成功！'
						});
						that.getData();
					}else{
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: res.message
						});
					}
				})
			},
			getAge(idcard){
				if(idcard!=''){
					var identityCard = idcard
					var len = identityCard.length;
					if (len == 0) {
						return 0;
					} else {
						if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
						{
							return 0;
						}
					}
					var strBirthday = "";
					if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
					{
						strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
					}
					if (len == 15) {
						strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
					}
					//时间字符串里，必须是“/”
					var birthDate = new Date(strBirthday);
					var nowDateTime = new Date();
					var age = nowDateTime.getFullYear() - birthDate.getFullYear();
					//再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
					if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
						age--;
					}
					return age;
				}
				return 0
			},
			back(){
				uni.navigateBack();
			},
			jump(path) {
				uni.navigateTo({
					url: path
				})
			}
		}
	}
</script>

<style scoped>
.uni-radio .uni-radio-input {
	width: 20rpx!important;
	height: 20rpx!important;
}
.uni-radio-input-checked {
	background-color: red!important;
}
.cu-btn{
	border-radius: 0;
}
.cu-item{
	height: 108rpx;
}
	.no_data{
		margin-top: 150rpx;
	}
	.no_data_img{
		margin-top: 150rpx;
	}
</style>
